﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problem17
{
    class Program
    {
        static Dictionary<int, string> numbers = new Dictionary<int, string>()
        {
            {1, "one"},
            {2, "two"},
            {3, "three"},
            {4, "four"},
            {5, "five"},
            {6, "six"},
            {7, "seven"},
            {8, "eight"},
            {9, "nine"},
            {10, "ten"},
            {11, "eleven"},
            {12, "twelve"},
            {13, "thirteen"},
            {14, "fourteen"},
            {15, "fifteen"},
            {16, "sixteen"},
            {17, "seventeen"},
            {18, "eighteen"},
            {19, "nineteen"},
            {20, "twenty"},
            {30, "thirty"},
            {40, "forty"},
            {50, "fifty"},
            {60, "sixty"},
            {70, "seventy"},
            {80, "eighty"},
            {90, "ninety"},
            {1000, "onethousand"}
        };

        static void Main(string[] args)
        {
            int totalSum = 0;

            for (int i = 1; i <= 1000; i++)
            {
                int n = i;
                int sum = 0;

                if (numbers.ContainsKey(n))
                {
                    sum += numbers[n].Length;
                }
                else
                {
                    if (n / 100 != 0)
                    {
                        sum += numbers[n / 100].Length + 7;

                        if (n % 100 != 0)
                        {
                            sum += 3;
                        }
                    }

                    n = n % 100;

                    if (numbers.ContainsKey(n))
                    {
                        sum += numbers[n].Length;
                    }
                    else
                    {
                        if (n / 10 != 0)
                        {
                            sum += numbers[n - n % 10].Length;
                        }
                        if (n % 10 != 0)
                        {
                            sum += numbers[n % 10].Length;
                        }
                    }
                }

                totalSum += sum;
            }

            Console.WriteLine(totalSum);
            Console.ReadKey();
        }
    }
}
